package com.tiancheng.trade.commom.core.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.Optional;

/**
 * 支付方式
 *
 * @author kellen
 * @date 2024/3/4
 */
@Getter
@AllArgsConstructor
public enum PaymentWayEnum implements BaseEnum<String> {

    WECHAT("wechat", "微信支付"),
    ALIPAY("alipay", "支付宝"),
    UNIONPAY("unionpay", "云闪付"),
    PAYPAL("paypal", "PayPal支付"),
    PAYINAPP("payinapp", "苹果内购"),
    DEDUCTION("deduction", "抵扣"),
    CORPPAY("corppay", "对公支付"),
    SCAN("scan", "扫码支付"),
    ;

    private final String code;
    private final String desc;

    public static Optional<PaymentWayEnum> getByCode(String code){
        return Arrays.stream(PaymentWayEnum.values()).filter(c -> c.code.equals(code)).findFirst();
    }
    public  static String getDesc(String code) {
        Optional<PaymentWayEnum> found = getByCode(code);
        if (found.isPresent()) {
            return found.get().getDesc();
        }
        return "";
    }
}
